import request from '/@/utils/request';
import { DeptData } from '/@/api/dept';
import { RoleData } from '/@/api/role';

export interface BaseUserInfo {
	userName: string;
	userNickname: string;
	roleSign: string;
	department: string[];
	phone: string;
	email: string;
	sex: Number;
	password: string;
	overdueTime: Date | String;
	status: boolean;
	describe: string;
}

export interface RuleFormRow extends BaseUserInfo{

}

export interface UserInfo {

}

// 定义接口来定义对象的类型
export interface TableDataRow extends BaseUserInfo {
	createTime: string;
}

export interface TableDataState {
	tableData: {
		queryData: QueryData,
		data: Array<TableDataRow>;
		total: number;
		loading: boolean;
		param: {
			pageNum: number;
			pageSize: number;
		};
	};
}

export interface QueryData  {
	username: String,
	phone: String,
}

export interface Sex {
	label: String,
	value: number,
}

export interface UserAddState {
	isShowDialog: boolean;
	ruleForm: BaseUserInfo;
	deptData: Array<DeptData>;
	roles: Array<RoleData>;
	sexes: Array<Sex>;
}

export interface UserEditState{
	isShowDialog: boolean;
	ruleForm: BaseUserInfo;
	sexes: Array<Sex>;
	deptData: Array<DeptData>;
}

export function userMenuApi() {
	return {

		getMenuAdmin: (params?: object) => {
			return request({
				url: '/gitee/lyt-top/vue-next-admin-images/raw/master/menu/adminMenu.json',
				method: 'get',
				params,
			});
		},

		getMenuTest: (params?: object) => {
			return request({
				url: '/gitee/lyt-top/vue-next-admin-images/raw/master/menu/testMenu.json',
				method: 'get',
				params,
			});
		},

		initData: (n: Number) => {
			const data: Array<TableDataRow> = [];
			for (let i = 0; i < n; i++) {
				data.push({
					userName: i === 0 ? 'admin' : 'test',
					userNickname: i === 0 ? '我是管理员' : '我是普通用户',
					roleSign: i === 0 ? 'admin' : 'common',
					department: i === 0 ? ['vueNextAdmin', 'IT外包服务'] : ['vueNextAdmin', '资本控股'],
					phone: '12345678910',
					email: 'vueNextAdmin@123.com',
					sex: i % 2  ,
					password: '123456',
					overdueTime: new Date(),
					status: true,
					describe: i === 0 ? '不可删除' : '测试用户',
					createTime: new Date().toLocaleString(),
				});
			}
			return data;
		},

		initSex: (() => {
			return [
				{
					label: '男',
					value: 1,
				}, {
					label: '女',
					value: 0,
				},
			];
		}),
	};
}
